package com.ruoyi.question.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.question.domain.EQuestionCategorization;
import com.ruoyi.question.service.IEQuestionCategorizationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 问题分类Controller
 *
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/categorization")
public class EQuestionCategorizationController extends BaseController
{
    @Autowired
    private IEQuestionCategorizationService eQuestionCategorizationService;

    /**
     * 查询问题分类列表
     */
    @RequiresPermissions("question:categorization:list")
    @GetMapping("/list")
    public TableDataInfo list(EQuestionCategorization eQuestionCategorization)
    {
        startPage();
        List<EQuestionCategorization> list = eQuestionCategorizationService.selectEQuestionCategorizationList(eQuestionCategorization);
        return getDataTable(list);
    }

    /**
     * 导出问题分类列表
     */
    @RequiresPermissions("question:categorization:export")
    @Log(title = "问题分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EQuestionCategorization eQuestionCategorization)
    {
        List<EQuestionCategorization> list = eQuestionCategorizationService.selectEQuestionCategorizationList(eQuestionCategorization);
        ExcelUtil<EQuestionCategorization> util = new ExcelUtil<EQuestionCategorization>(EQuestionCategorization.class);
        util.exportExcel(response, list, "问题分类数据");
    }

    /**
     * 获取问题分类详细信息
     */
    @RequiresPermissions("question:categorization:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eQuestionCategorizationService.selectEQuestionCategorizationById(id));
    }

    /**
     * 新增问题分类
     */
    @RequiresPermissions("question:categorization:add")
    @Log(title = "问题分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EQuestionCategorization eQuestionCategorization)
    {
        return toAjax(eQuestionCategorizationService.insertEQuestionCategorization(eQuestionCategorization));
    }

    /**
     * 修改问题分类
     */
    @RequiresPermissions("question:categorization:edit")
    @Log(title = "问题分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EQuestionCategorization eQuestionCategorization)
    {
        return toAjax(eQuestionCategorizationService.updateEQuestionCategorization(eQuestionCategorization));
    }

    /**
     * 删除问题分类
     */
    @RequiresPermissions("question:categorization:remove")
    @Log(title = "问题分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eQuestionCategorizationService.deleteEQuestionCategorizationByIds(ids));
    }

    /*
    * 查询问题分类中文列表
    * */
    @GetMapping("selectChineseNomenclatureList")
    public AjaxResult selectChineseNomenclatureList(){
        return success(eQuestionCategorizationService.selectChineseNomenclatureList());
    }

    /*
    * 禁用/启用功能
    * */
    @PutMapping("updateEQuestionCategorizationStatus")
    public AjaxResult updateEQuestionCategorizationStatus(@RequestBody EQuestionCategorization eQuestionCategorization){
        return toAjax(eQuestionCategorizationService.updateEQuestionCategorizationStatus(eQuestionCategorization));
    }

    /*
    * 修改问题分类的引用状态
    * */
    @PutMapping("updateCategorizationReferenceStatus")
    public AjaxResult updateCategorizationReferenceStatus(@RequestBody Long id){
        return toAjax(eQuestionCategorizationService.updateCategorizationReferenceStatus(id));
    }
}
